import '../../util/_base_export.dart';
import '../../util/_view_export.dart';

class ProductItemComponent extends StatelessWidget {
  final String iv_img;
  final String iv_name;
  final String iv_price;
  final GlobalKey iv_rootkey;
  final Offset iv_offset;

  ProductItemComponent({
    Key? key,
    required this.iv_img,
    required this.iv_name,
    required this.iv_price,
    required this.iv_rootkey,
    required this.iv_offset,
  }) : super(key: key);

  Widget build(BuildContext context) {
    late Offset temp;
    return Container(
      padding: EdgeInsets.all(22.w),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        children: <Widget>[
          Container(
            width: 120.w,
            height: 120.h,
            child: Image.asset(iv_img),

            // CachedNetworkImage(
            //   imageUrl: iv_img,
            //   fit: BoxFit.cover,
            // ),
          ),
          Container(
            // padding: EdgeInsets.symmetric(
            //       vertical: 2.h,
            //       horizontal: 15.w,
            //     ),

            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              // crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Container(
                  // height: 110.h,

                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Text(
                        iv_name,
                        softWrap: true,
                        maxLines: 1,
                        overflow: TextOverflow.ellipsis,
                        style: TextStyle(
                          color: AppColor.nameProduct,
                          fontWeight: FontWeight.normal,
                          fontSize: 15.sp,
                        ),
                      ),
                      // Text(
                      //   " ",
                      //   style: TextStyle(
                      //     color: AppColor.priceProduct,
                      //     fontWeight: FontWeight.normal,
                      //     fontSize: 15.sp,
                      //   ),
                      // ),
                      Text(
                        iv_price,
                        softWrap: true,
                        maxLines: 1,
                        overflow: TextOverflow.fade,
                        style: TextStyle(
                          color: AppColor.priceProduct,
                          fontWeight: FontWeight.normal,
                          fontSize: 15.sp,
                        ),
                      ),
                    ],
                  ),
                ),
                Container(
                  alignment: Alignment(1.0, 1.0),
                  child: Row(
                    children: <Widget>[
                      GestureDetector(
                        onPanDown: (details) {
                          temp = new Offset(details.globalPosition.dx, details.globalPosition.dy);
                        },
                        onTap: () {
                          late Function callback;
                          // setState(() {
                          OverlayEntry entry = OverlayEntry(builder: (ctx) {
//                RenderBox renderBox = itemKey.currentContext.findRenderObject();
//                Offset itemOffset = renderBox.localToGlobal(Offset.zero,
//                    ancestor: rootKey.currentContext.findRenderObject());
//                print("item offset  :${itemOffset.toString()}    float offset"
//                    " ${floatOffset.toString()}");
                            /// root key：根widget key， 主要用于定位
                            /// temp:点击坐标，开始位置。floatOffset 结束坐标
                            ///Icon：传入想弹出的widget
                            ///call back: 会回传一个动画执行状态
                            ///duration： 动画时间 可选，默认1秒
                            ///

                            return ParabolaAnimateWidget(
                              iv_rootkey,
                              temp,
                              iv_offset,
                              Icon(
                                Icons.cancel,
                                color: Colors.greenAccent,
                              ),
                              callback,
                              duration: 2,
                            );
                          });

                          callback = (status) {
                            if (status == AnimationStatus.completed) {
                              entry.remove();
                            }
                          };

                          Overlay.of(iv_rootkey.currentContext!)!.insert(entry);
                          // });
                        },
                        child: IconButton(
                          icon: Icon(
                              // MaterialCommunityIcons.minus_circle_outline
                              LineIcons.minusCircle
                          ),
                          onPressed: null,
                        ),
                      ),
                      IconButton(
                        icon: Icon(
                            // MaterialCommunityIcons.plus_circle
                            LineIcons.plusCircle
                        ),
                        onPressed: null,
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
